package com.example.mobile2030606150cjk0615;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class UsersRViewAdapter extends RecyclerView.Adapter<UsersRViewAdapter.ViewHolder> {
    private List<Users> list;
    public UsersRViewAdapter(List<Users> list) {
        this.list = list;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItenId, tvItenNane , tvItenAge, tvItenScore ;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItenId = itemView.findViewById(R.id.tvItemId);
            tvItenNane = itemView.findViewById(R.id.tvItenNane);
            tvItenAge = itemView.findViewById(R.id.tvItenAge);
            tvItenScore = itemView.findViewById(R.id.tvItenScore);
        }
    }
    @NonNull
    @Override
    public UsersRViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_user, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull UsersRViewAdapter.ViewHolder holder, int position) {
        Users users = list.get(position);
        holder.tvItenId.setText(String.valueOf(users.get_id()));
        holder.tvItenNane.setText(users.getName());
        holder.tvItenAge.setText(String.valueOf(users.getAge()));
        holder.tvItenScore.setText(String.valueOf(users.getScore()));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
